Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to share a preconfigured diff scene #1158

Open
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

patnir41
Copy link
Contributor

Selecting comparison options in diff scenes will update an opts parameter in the URL, which is used to drive the state of the selected options in the scene.

@patnir41
Copy link
Contributor Author

patnir41 commented Aug 18, 2022

(For @josephaxisa) I created a new branch from the previous PR. After making some final changes to that PR and merging it into main, I merged main into this branch. I thought conflicts were resolved until I pushed and saw there were still some conflicts which I resolved in the GitHub editor. Let me know if there's anything I could/should have done differently.

@github-actions
Copy link
Contributor

APIX Tests

    1 files  ±0    86 suites  +2   5m 36s ⏱️ +6s
400 tests +8  386 ✔️ +7  13 💤 ±0  1 ❌ +1 
420 runs  +8  406 ✔️ +7  13 💤 ±0  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 358c56c. ± Comparison against base commit 135dce3.

@@ -54,9 +54,9 @@ export const SideNavMethods = styled(
const _isOpen = !isOpen
setIsOpen(_isOpen)
if (_isOpen) {
navigate(`/${specKey}/methods/${tag}`)
navigate(`/${specKey}/methods/${tag}`, { opts: null })
Copy link
Contributor Author

@patnir41 patnir41 Aug 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scenario to consider here (and with the same change in SideNavTypes): we are in a diff scene with selected options, and opts param in the url. When we open the sideNav and open a method/tag scene, this opts parameter should no longer persist. The reason we don't use navigateWithGlobalParams to remove this parameter is because if we started at a tag scene with a filter selected and want to select another tag, this filter should still persist when we open the new tag scene.

So, technically, the purpose of this line in plain english is more like "navigate to the tag scene and ONLY keep the tag filter variable if we have one in the URL"

This makes me reconsider what we initially had proposed where we have a specific navigateTo methods. I think in the long term there will be 2 cases:

  1. We navigate to a scene, remove all scene-specific params first, then push global params (currently the case with navigateWithGlobalParams, etc)
  2. We navigate to a scene, keeping ONLY specific parameters, and removing anything else in the URL.

To better account for case 2, I think having custom navigate methods makes the most sense. Here we'd explicitly have a navigateToTagScene instead of having to explicitly nullify any extra parameters that could persist when navigating to a tag scene from the SideNav.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const diffOptionsParam = getDiffOptionsFromUrl(params.get('opts'))
if (diffOptionsParam) {
setDiffOptionsAction({ diffOptions: diffOptionsParam })
navigate(location.pathname, { opts: diffOptionsParam.join(',') })
Copy link
Contributor Author

@patnir41 patnir41 Aug 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this navigate here, which contrasts from tagStoreSync or globalStoreSync where we only dispatch to the store, is in the case where we have a list of options in the url, but one or more of those are not actually valid comparison options for the diff scene (e.g. opts=missing%2CINVALID%2Ctype)

getValidDiffOptions does the job of filtering out invalid comparison options from the URL and navigate does the job of updating the URL to only have the valid options out of those listed in the parameter.

@github-actions
Copy link
Contributor

APIX Tests

0 files   -     1  0 suites   - 84   0s ⏱️ - 8m 16s
0 tests  - 392  0 ✔️  - 379  0 💤  - 13  0 ❌ ±0 
0 runs   - 412  0 ✔️  - 399  0 💤  - 13  0 ❌ ±0 

Results for commit a6a47ca. ± Comparison against base commit 180cf20.

This pull request removes 392 tests.
 DocTitle renders a heading with title prop content ‑  DocTitle renders a heading with title prop content
 MethodBadge renders with the provided verb ‑  MethodBadge renders with the provided verb
ApiSpecSelector it lists all available specs ‑ ApiSpecSelector it lists all available specs
ApiSpecSelector requests selected spec ‑ ApiSpecSelector requests selected spec
ApiSpecSelector the base spec is selected by default ‑ ApiSpecSelector the base spec is selected by default
Banner renders with button that opens api 4.0 dev portal link in new page ‑ Banner renders with button that opens api 4.0 dev portal link in new page
Banner sets local storage value and unrenders on close button click ‑ Banner sets local storage value and unrenders on close button click
BrowserAdaptor copies location href to clipboard ‑ BrowserAdaptor copies location href to clipboard
BrowserAdaptor returns correct font overrides ‑ BrowserAdaptor returns correct font overrides
CodeCopy displays code and clipboard UI ‑ CodeCopy displays code and clipboard UI
…

@github-actions
Copy link
Contributor

APIX Tests

0 files   -     1  0 suites   - 84   0s ⏱️ - 8m 16s
0 tests  - 392  0 ✔️  - 379  0 💤  - 13  0 ❌ ±0 
0 runs   - 412  0 ✔️  - 399  0 💤  - 13  0 ❌ ±0 

Results for commit d92df04. ± Comparison against base commit 180cf20.

This pull request removes 392 tests.
 DocTitle renders a heading with title prop content ‑  DocTitle renders a heading with title prop content
 MethodBadge renders with the provided verb ‑  MethodBadge renders with the provided verb
ApiSpecSelector it lists all available specs ‑ ApiSpecSelector it lists all available specs
ApiSpecSelector requests selected spec ‑ ApiSpecSelector requests selected spec
ApiSpecSelector the base spec is selected by default ‑ ApiSpecSelector the base spec is selected by default
Banner renders with button that opens api 4.0 dev portal link in new page ‑ Banner renders with button that opens api 4.0 dev portal link in new page
Banner sets local storage value and unrenders on close button click ‑ Banner sets local storage value and unrenders on close button click
BrowserAdaptor copies location href to clipboard ‑ BrowserAdaptor copies location href to clipboard
BrowserAdaptor returns correct font overrides ‑ BrowserAdaptor returns correct font overrides
CodeCopy displays code and clipboard UI ‑ CodeCopy displays code and clipboard UI
…

@github-actions
Copy link
Contributor

APIX Tests

0 files   -     1  0 suites   - 84   0s ⏱️ - 8m 16s
0 tests  - 392  0 ✔️  - 379  0 💤  - 13  0 ❌ ±0 
0 runs   - 412  0 ✔️  - 399  0 💤  - 13  0 ❌ ±0 

Results for commit 377dac8. ± Comparison against base commit 180cf20.

This pull request removes 392 tests.
 DocTitle renders a heading with title prop content ‑  DocTitle renders a heading with title prop content
 MethodBadge renders with the provided verb ‑  MethodBadge renders with the provided verb
ApiSpecSelector it lists all available specs ‑ ApiSpecSelector it lists all available specs
ApiSpecSelector requests selected spec ‑ ApiSpecSelector requests selected spec
ApiSpecSelector the base spec is selected by default ‑ ApiSpecSelector the base spec is selected by default
Banner renders with button that opens api 4.0 dev portal link in new page ‑ Banner renders with button that opens api 4.0 dev portal link in new page
Banner sets local storage value and unrenders on close button click ‑ Banner sets local storage value and unrenders on close button click
BrowserAdaptor copies location href to clipboard ‑ BrowserAdaptor copies location href to clipboard
BrowserAdaptor returns correct font overrides ‑ BrowserAdaptor returns correct font overrides
CodeCopy displays code and clipboard UI ‑ CodeCopy displays code and clipboard UI
…

@github-actions
Copy link
Contributor

APIX Tests

0 files   -     1  0 suites   - 86   0s ⏱️ - 6m 34s
0 tests  - 408  0 ✔️  - 395  0 💤  - 13  0 ❌ ±0 
0 runs   - 428  0 ✔️  - 415  0 💤  - 13  0 ❌ ±0 

Results for commit 73ca49c. ± Comparison against base commit a4ac3bc.

This pull request removes 408 tests.
 DocTitle renders a heading with title prop content ‑  DocTitle renders a heading with title prop content
 MethodBadge renders with the provided verb ‑  MethodBadge renders with the provided verb
APIErrorDialog defaults an empty error message ‑ APIErrorDialog defaults an empty error message
APIErrorDialog is hidden if open is false ‑ APIErrorDialog is hidden if open is false
APIErrorDialog ok button click fires ‑ APIErrorDialog ok button click fires
APIErrorDialog shows detailed errors ‑ APIErrorDialog shows detailed errors
APIErrorDialog shows simple errors ‑ APIErrorDialog shows simple errors
APIErrorDialog skips empty documentation url ‑ APIErrorDialog skips empty documentation url
APIErrorDisplay defaults an empty error message ‑ APIErrorDisplay defaults an empty error message
APIErrorDisplay fetches error doc ‑ APIErrorDisplay fetches error doc
…

@@ -265,4 +270,70 @@ describe('Diff Scene', () => {
expect(diff40to31Page1Methods).toHaveLength(15)
expect(diff40to31Page1Methods).toContain('delete_board_item')
})

it('updates when a comparison option is toggled', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this, but I thought it would be nice to have an integration test ensuring the DiffScene operates properly other than the unit tests which I couldn't make comprehensive due to the spec file bug.

@patnir41 patnir41 marked this pull request as ready for review September 6, 2022 17:13
@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2022

APIX Tests

    1 files    88 suites   6m 9s ⏱️
422 tests 409 ✔️ 13 💤 0 ❌
442 runs  429 ✔️ 13 💤 0 ❌

Results for commit a8965ea.

Copy link
Contributor

@josephaxisa josephaxisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Niral. I noted some feedback below

@@ -55,9 +54,9 @@ export const SideNavMethods = styled(
const _isOpen = !isOpen
setIsOpen(_isOpen)
if (_isOpen) {
navigateWithGlobalParams(`/${specKey}/methods/${tag}`)
navigate(`/${specKey}/methods/${tag}`, { opts: null })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not navigateWithGlobalParams?

@@ -54,9 +54,9 @@ export const SideNavTypes = styled(
const _isOpen = !isOpen
setIsOpen(_isOpen)
if (_isOpen) {
navigate(`/${specKey}/types/${tag}`)
navigate(`/${specKey}/types/${tag}`, { opts: null })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

} else {
navigate(`/${specKey}/types`)
navigate(`/${specKey}/types`, { opts: null })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

} else {
navigateWithGlobalParams(`/${specKey}/methods`)
navigate(`/${specKey}/methods`, { opts: null })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

expect(mockHistoryPush).toHaveBeenCalledWith(`/${specKey}/methods/${tag}`)
expect(mockHistoryPush).toHaveBeenCalledWith({
pathname: `/${specKey}/methods/${tag}`,
search: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change won't be needed if navigateWithGlobalParams is used.

Comment on lines +104 to +107
expect(mockHistoryPush).toHaveBeenCalledWith({
pathname: `/${specKey}/methods`,
search: '',
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

packages/api-explorer/src/scenes/DiffScene/diffUtils.ts Outdated Show resolved Hide resolved
* Returns all valid diff options contained in list
* @param opts url diff options parameter value
*/
export const getValidDiffOptions = (opts: string | null) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can opts just be made an optional string arg here? is null explicitly needed?

Copy link
Contributor Author

@patnir41 patnir41 Sep 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pass in searchParams.get('opts') in both DiffScene and diffStoreSync. When the param doesn't exist in the URL it searchParams.get() will return null, so this was just a way to be able to handle it without doing any explicit checks before passing it in as input.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2022

APIX Tests

    1 files  ±  0    88 suites  +2   8m 6s ⏱️ + 2m 14s
422 tests +14  409 ✔️ +14  13 💤 ±0  0 ❌ ±0 
442 runs  +14  429 ✔️ +14  13 💤 ±0  0 ❌ ±0 

Results for commit c34fdee. ± Comparison against base commit 0db7157.

@github-actions
Copy link
Contributor

APIX Tests

    1 files    88 suites   7m 50s ⏱️
422 tests 409 ✔️ 13 💤 0 ❌
442 runs  429 ✔️ 13 💤 0 ❌

Results for commit 09a0666.

@github-actions
Copy link
Contributor

APIX Tests

    1 files    88 suites   6m 9s ⏱️
422 tests 409 ✔️ 13 💤 0 ❌
442 runs  429 ✔️ 13 💤 0 ❌

Results for commit c54f9b3.

@patnir41 patnir41 requested a review from a team as a code owner March 12, 2024 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants